<?
require_once("inc_security.php");
//check quy?n them sua xoa
checkAddEdit("add");

	//Khai bao Bien
	$record_id 								= getValue("record_id");
    
    $cateop = get_all_faq_cate_options();
    
    $action = getValue('action', 'str', 'POST', '');
	//Call Class generate_form();
	$myform = new generate_form();
	//Lo?i b? chuc nang thay the Tag Html
	$myform->removeHTML(0);

	//Add table
	$myform->addTable($fs_table);
    
	//Warning Error!
	$errorMsg = "";
	
	if($action == 'edit' && isset($_POST['submit'])){
		$far_name								= getValue("far_name","str","GET","");
        $far_content								= getValue("far_content","str","GET","");
    	$far_fac_id								= getValue("far_fac_id","int","GET",'0');
        
		
        $myform->add("far_name","far_name", 0, 0, $far_name, 1, translate_text("Tên câu hỏi không được để trống"), 0, "");
        $myform->add("far_content","far_content", 0, 0, $far_content, 1, translate_text("Nội dung không được để trống"), 0, "");
        $myform->add("far_fac_id", "far_fac_id", 1, 0, $far_fac_id, 1, translate_text("Vui lòng chọn danh mục"),0,"");
        
		$errorMsg .= $myform->checkdata();
		if($errorMsg == ""){
			
            $db_ex = new db_execute($myform->generate_update_SQL($id_field, $record_id));
            
			redirect($listing);
			exit();
		}
	}
	//add form for javacheck
	$myform->addFormname('faq_edit');
	$myform->evaluate();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?=$load_header?>
<? 
$myform->checkjavascript();
$errorMsg .= $myform->strErrorField;

//lay du lieu cua record can sua doi
$db_data = new db_query("SELECT * FROM " . $fs_table . " WHERE " . $id_field . " = " . $record_id);
$row = mysql_fetch_assoc($db_data->result);
if(!$row){
    redirect($listing);
    exit;
}
?>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<? /*------------------------------------------------------------------------------------------------*/ ?>
<?=template_top(translate_text("Edit_category"))?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
	<p align="center" style="padding-left:10px;">
    <?php
    $form = new form();
    $form->create_form("faq_edit", $_SERVER["REQUEST_URI"], "post", "multipart/form-data",'onsubmit="validateForm(); return false;"');
	$form->create_table();
	?>
	<?=$form->text_note('Những ô dấu (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
	<?=$form->errorMsg($errorMsg)?>
    
	<?=$form->text("Câu hỏi", "far_name", "far_name", $row['far_name'], "Câu hỏi", 1, 250, "", 255, "", "", "")?>
    <?=$form->select("Danh mục", "far_fac_id", "far_fac_id", $cateop, $row['far_fac_id'], "Danh mục", 0, 250, 1, 0,  "", "")?>
    <? $form->close_table();?>
    <?=$form->tinyMCE("Nội dung", "far_content", "far_content", $row['far_content'])?>
    <?=$form->create_table();?>
    
	<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
	<?=$form->hidden("action", "action", "edit", "");?>
    
	<?
	$form->close_table();
	$form->close_form();
	unset($form);
	?>
	</p>
<?=template_bottom() ?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
</body>
</html>